<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010-2011 GioCMS (http://cms.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @author		NinhGio - ninhgio@gmail.com
 * @since		1.0
 * @version		$Id: list.phtml 113 2011-04-11 17:36:03Z ninhgio@gmail.com $
 */

$this->headTitle($this->TRANSLATOR->translator('template_list_page_title') . ' - ' . $this->TRANSLATOR->translator('common_admin_title', 'core'));
?>
<div class="content">
	<div class="box header mb0">
		<div class="head"><div></div></div>
		<h2 class="g_a_breadcump">
			<a class="fl" href="<?php echo $this->url('core_dashboard_index'); ?>"><?php echo $this->TRANSLATOR->translator('dashboard_breadcump', 'core'); ?></a>
			<small class="icon arrow_right" style="display: block;"></small>
			<a class="fl" href="javascript: void(0);"><?php echo $this->TRANSLATOR->translator('mail_breadcump'); ?></a>
			<small class="icon arrow_right" style="display: block;"></small>
			<a class="fl" href="<?php echo $this->url('mail_template_list'); ?>"><?php echo $this->TRANSLATOR->translator('template_breadcump'); ?></a>
			<small class="icon arrow_right" style="display: block;"></small>
			<a class="fl" href="javascript: void(0);"><?php echo $this->TRANSLATOR->translator('template_list_breadcump'); ?></a>
			<div class="clear"></div>
		</h2>
	</div>
</div>
<div class="content">
	<div class="desc">
		<div class="body">
			<div class="fl">
				<h4 class="g_a_h4"><?php echo $this->TRANSLATOR->translator('template_list_guide'); ?></h4>
			</div>
			<div class="fr">
				<a class="fl g_a_tip g_a_cancel_button mr5" href="javascript: history.go(-1);" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('common_back_button', 'core')); ?>"></a>
				<?php if ($this->ACL->isAllowed('list', 'template')) : ?>
				<a class="fl g_a_tip" href="<?php echo $this->url('mail_template_list'); ?>" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('template_list_title')); ?>">
					<img src="<?php echo $this->APP_RESOURCE_SERVER; ?>/templates/<?php echo $this->APP_TEMPLATE; ?>/skins/<?php echo $this->APP_SKIN; ?>/images/actions_list_icon.png" style="padding: 0 5px 0 0;" />
				</a>
				<?php endif; ?>
				<?php if ($this->ACL->isAllowed('add', 'template')) : ?>
				<a class="fl g_a_tip" href="<?php echo $this->url('mail_template_add'); ?>" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('template_add_title')); ?>">
					<img src="<?php echo $this->APP_RESOURCE_SERVER; ?>/templates/<?php echo $this->APP_TEMPLATE; ?>/skins/<?php echo $this->APP_SKIN; ?>/images/actions_add_icon.png" style="padding: 0 5px 0 0;" />
				</a>
				<?php endif; ?>
			</div>
			<div class="g_a_line"></div>
			<!--  -->
			<!--  -->
			<?php if (isset($this->pager)) : ?>	
			<!-- Pager -->
			<div class="module pagination g_a_pager">
				<?php echo $this->pager->links; ?>
			</div>
			<!-- / Pager -->
			<?php endif; ?>	
			<div class="clear"></div>
			<table class="g_a_data_table">
				<tbody>
					<tr>
						<th class="checkbox w_1"><input type="checkbox" name="checkbox"></th>
						<th title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('template_title_description')); ?>" class="g_a_tip_top"><?php echo $this->TRANSLATOR->translator('template_title'); ?></th>
						<th title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('template_name_description')); ?>" class="g_a_tip_top w_20"><?php echo $this->TRANSLATOR->translator('template_name'); ?></th>
						<th title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('template_from_mail_description')); ?>" class="g_a_tip_top w_20"><?php echo $this->TRANSLATOR->translator('template_from_mail'); ?></th>
						<th title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('template_id')); ?>" class="g_a_tip_top w_7"><?php echo $this->TRANSLATOR->translator('template_id'); ?></th>
					</tr>
					<?php if (isset($this->numTemplates) && $this->numTemplates > 0) : ?>
					<?php foreach ($this->templates as $index => $template) : ?>
					<tr class="g_a_row" id="gMailTemplateRow_<?php echo $template['template_id']; ?>">
						<td class="checkbox w_1"><input type="checkbox" name="checkbox"></td>
						<td>
							<div class="content"><strong><?php echo $template['title']; ?></strong></div>
							<div class="clear"></div>
							<div class="g_a_actions buttons_demo" style="margin-top: 5px;">
								<?php if ($this->ACL->isAllowed('edit', 'template')) : ?>
								<a class="button yellow" href="<?php echo $this->url('mail_template_edit', $template); ?>"><small class="icon pencil"></small><span><?php echo $this->TRANSLATOR->translator('template_list_edit'); ?></span></a>
								<?php endif; ?>
								<?php if ($this->ACL->isAllowed('delete', 'template')) : ?>
								<a class="button red g_a_actions_ojbect" rel="delete_<?php echo $template['template_id']; ?>" href="javascript: void(0);"><small class="icon cross"></small><span><?php echo $this->TRANSLATOR->translator('template_list_delete'); ?></span></a>
								<?php endif; ?>
								<div class="clear"></div>
							</div>
						</td>
						<td><?php echo $template['name']; ?></td>
						<td><?php echo $template['from_mail']; ?></td>
						<td class="w_5"><?php echo $template['template_id']; ?></td>
					</tr>
					<?php endforeach; ?>
					<?php else : ?>
					<tr>
						<td colspan="5"><p><?php echo $this->TRANSLATOR->translator('template_list_data_notfound'); ?></p></td>
					</tr>
					<?php endif; ?>
				</tbody>
			</table>
			<!--  -->
			<?php if (isset($this->pager)) : ?>	
			<!-- Pager -->
			<div class="module pagination g_a_pager">
				<?php echo $this->pager->links; ?>
			</div>
			<!-- / Pager -->
			<?php endif; ?>	
			<div class="clear"></div>
		</div>
	</div>
	<div class="body_footer">
		<div class="bottom_left"><div class="bottom_right"></div></div>
	</div>
</div>
<!--  -->
<script type="text/javascript">
'Gio.Mail.Template'.namespace();
Gio.Mail.Template.currenAction = null;
Gio.Mail.Template.actions = function(params) {
	/**
	 * Show g_a_ajax_loading element
	 */
	$('#g_a_ajax_loading').show();
	$.ajaxq('mail_template_action', {
		type: 'post',
		url: params.url,
		data: params,
		success: function(response) {
			if (response == 'RESULT_OK') {
				var type = 'success';
				$('#gMailTemplateRow_' + params.template_id).addClass('g_a_row_affected');
				switch (params.act) {
					case 'delete':
						var message = '<?php echo $this->STRING->escape($this->TRANSLATOR->translator('template_list_delete_success')); ?>';
						$('#gMailTemplateRow_' + params.template_id).fadeOut('slow');
						break;
					case 'activate':
					case 'deactivate':
						var rel = (params.act == 'activate') ? 'deactivate_' + params.template_id : 'activate_' + params.template_id;
						var className = (params.act == 'activate') ? 'lock' : 'unlock';
						var text = (params.act == 'activate') ? '<?php echo $this->TRANSLATOR->translator('template_list_deactivate'); ?>' : '<?php echo $this->TRANSLATOR->translator('template_list_activate'); ?>';
						var textStatus = (params.act == 'activate') ? '<?php echo $this->TRANSLATOR->translator('template_status_active'); ?>' : '<?php echo $this->TRANSLATOR->translator('template_status_inactive'); ?>';
						var message = (params.act == 'activate') ? '<?php echo $this->TRANSLATOR->translator('template_list_activate_success'); ?>' : '<?php echo $this->TRANSLATOR->translator('template_list_deactivate_success'); ?>';

						$(Gio.Mail.Template.currenAction).attr('rel', rel);
						$(Gio.Mail.Template.currenAction).children('small:first').removeClass('lock')
														.removeClass('unlock')
														.addClass(className);
						$(Gio.Mail.Template.currenAction).children('span:first').html(text);
						$('#gMailTemplateStatus_' + params.template_id).html(textStatus);
						break;
				}
				Gio.Message.success(message);
			} else {
				Gio.Message.error('<?php echo $this->STRING->escape($this->TRANSLATOR->translator('common_error_message', 'core')); ?>');
			}
			/**
			 * Hide g_a_ajax_loading element
			 */
			$('#g_a_ajax_loading').hide();
		}
	});
};

$(document).ready(function() {
	$('.g_a_actions .g_a_actions_ojbect').each(function() {
		var self = this;
		$(self).bind('click', function() {
			Gio.Mail.Template.currenAction = this;
			var stringId = $(this).attr('rel');
			var temp = stringId.split('_');
			var act = temp[0];
			var id = temp[1];
			var url = ''; 
			switch (act) {
				case 'delete':
					url = '<?php echo $this->url('mail_template_delete'); ?>';
					var messsage_confirm = '<?php echo $this->STRING->escape($this->TRANSLATOR->translator('template_list_delete_confirm')); ?>';
					break;
				case 'activate':
				case 'deactivate':
					url = '<?php echo $this->url('mail_template_activate'); ?>';
					var messsage_confirm = (act == 'activate') 
												? '<?php echo $this->STRING->escape($this->TRANSLATOR->translator('template_list_activate_confirm')); ?>'
												: '<?php echo $this->STRING->escape($this->TRANSLATOR->translator('template_list_deactivate_confirm')); ?>';
					break;
			}
			data = { url: url, template_id: id, act: act };
			Gio.Message.yesButton = '<?php echo $this->STRING->escape($this->TRANSLATOR->translator('common_yes_button', 'core')); ?>';
			Gio.Message.noButton = '<?php echo $this->STRING->escape($this->TRANSLATOR->translator('common_no_button', 'core')); ?>';
			Gio.Message.confirm(messsage_confirm, 'Gio.Mail.Template.actions', data);
		});
	});
});
</script>